package com.AUI.components
{
	import com.AUI.*;
	
	import flash.display.*;
	
	/**
	 * Table row.
	 * @author HuangMinPing
	 * @site www.AminLab.com
	 */
	public class Tr extends H
	{
		/**
		 * Constructor.
		 */
		public function Tr()
		{
			// init attributes
			depth = 3;
			
			/**************** INITCOMPLETE ****************/
			Object(this).constructor == Tr && initComplete();
		}
		/**
		 * Get or set a string array that indicates the name of items of the List.
		 */
		override public function set value(variable:*):void
		{
			var items:Array = variable as Array;
			var cur:int = numElements;
			var end:int = items ? items.length : 0;
			// append item
			while(cur < end)
			{
				elements.addChild(new Td);
				++cur;
			}
			// delete item
			while(cur > end)
			{
				elements.removeChildAt(0);
				--cur;
			}
			// update item's value
			for(var i:int = 0;i < end;++i)
			{
				var item:AComponent = AComponent(getElementAt(i));
				item.value = items[i];
			}
			// update
			updateAlignment();
			updateContentBox();
		}
		override public function get value():*
		{
			var len:int = numElements;
			var items:Array = new Array(len);
			for(var i:int = 0;i < len;++i)
			{
				items[i] = AComponent(getElementAt(i)).value;
			}
			return items;
		}
		/**
		 * @private
		 */
		override protected function resizeBoxModel():void
		{
			super.resizeBoxModel();
			// update cells' width
			var width:int = boxModel.content.width / numElements;
			for(var i:int = 0,len:int = numElements;i < len;++i)
			{
				var unit:DisplayObject = getElementAt(i);
				unit.width = width;
				unit.height = boxModel.content.height;
			}
			this.updateAlignment();
		}
		/**
		 * @private.
		 */
		override protected function updateDrawStyle():void
		{
			super.updateDrawStyle();
			for(var i:int = 0,len:int = numElements;i < len;++i)
			{
				var td:Td = Td(getElementAt(i));
				if(drawStyle.font.compare(td.style.font) == false)
				{
					drawStyle.font.cloneTo(td.style.font);
					td.updateStyle();
				}
			}
		}
	}
}